﻿using EMS.system.Entityies.BaseData;
using EMS.system.Entityies.MasterData.WorkstationModel;
using EMS.system.IEntityAppService.MasterData.WorkstationService;
using EMS.system.IEntityAppService.MasterData.WorkstationService.WorkstationDTOs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.Host;
using Polly.Caching;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.MasterData.Workstations
{
    public class WorkstationController : Controller
    {
        /// <summary>
        /// 工作站服务类
        /// </summary>
        private readonly IWorkstationAppService _workstationAppService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="workspaceService"></param>
        public WorkstationController(IWorkstationAppService workstationAppService)
        {
            _workstationAppService = workstationAppService;
        }
        /// <summary>
        /// 工作站显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkstationList()
        {
            return View();
        }
        /// <summary>
        /// 工作站添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult CreateWorkstation()
        {
            return View();
        }
        /// <summary>
        /// 工作站更新视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateWorkstation(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 获取工作站显示 分页 查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="workstationCode"></param>
        /// <param name="workstationName"></param>
        /// <param name="workshopName"></param>
        /// <param name="processBelongs"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task< JsonResult>  GetWorkstationList(int page, int limit, string? workstationName, string? workshopName)
        {
            var workstation = await _workstationAppService.GetWorkstationList(page, limit, workstationName, workshopName);
            return  Json(new { code = 0, data = workstation.Queryable, count = workstation.RowCount });
        }
        /// <summary>
        /// 获取字典表数据绑定下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DictItem>> GetDictItems(int dictTypeId)
        {
            return await _workstationAppService.GetDictItemListRedis(dictTypeId);
        }
        /// <summary>
        /// 添加工作站
        /// </summary>
        /// <param name="workstationDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task< int> CreateWorkstation(WorkstationDTO workstationDTO)
        {
            return await _workstationAppService.CreateWorkstation(workstationDTO);
        }
        /// <summary>
        /// 删除工作站
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteWorkstation(string ids)
        {
            return await _workstationAppService.DeleteWorkstation(ids);
        }
        /// <summary>
        /// 获取工作站主键id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<WorkstationDTO> GetWorkstationById(int id)
        {
            ViewBag.Id = id;
            return await _workstationAppService.GetWorkstationById(id);
        }

        /// <summary>
        /// 更新工作站
        /// </summary>
        /// <param name="workstationDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateWorkstation(WorkstationDTO workstationDTO)
        {
            return await _workstationAppService.UpdateWorkstation(workstationDTO);

        }
    }
}
